//
//  WebViewController.m
//  UI_中关村
//
//  Created by dllo on 15/10/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "WebViewController.h"
#import "FirstViewController.h"

@interface WebViewController ()<UIWebViewDelegate>
@property(nonatomic, retain)UIActivityIndicatorView *acView;
@property (nonatomic,copy) NSString *name;
@property (nonatomic, retain) UIImageView *imageView;
@end

@implementation WebViewController
- (void)dealloc {
    [_url release];
    [_acView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSLog(@"1111111111111111111111111111111%@", self.url);
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -25, 375, 693)];
    [self.view addSubview:webView];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(-1, -1, 377, 65)];
    headView.backgroundColor = [UIColor whiteColor];
    headView.layer.borderWidth = 1;
    headView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [self.view addSubview:headView];
    
    self.acView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 32.0f, 32.0f)];
    self.acView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    self.acView.center = self.view.center;
    [self.view addSubview:self.acView];
    [_acView release];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    [webView loadRequest:request];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 14, 50, 50);
    [headView addSubview:button];
    [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"iconfont-arrow-left-line.png"] forState:UIControlStateNormal];
    
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", @"login_avatar_default@2x.png", nil];
    
    for (int i = 0; i < array.count; i++) {
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 118 * (i % 3), 80 + 118 * (i / 3), 98, 98)];
        self.name = [array objectAtIndex:i];
        self.imageView.image = [UIImage imageNamed:self.name];
        [self.view addSubview:self.imageView];
        [self.imageView release];
        
        self.imageView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self.imageView addGestureRecognizer:tap];
        [tap release];
        
    }

    
    
}

-(void)tapAction:(UITapGestureRecognizer *)tap
{
    
    FirstViewController *first = [[FirstViewController alloc] init];
    
    first.string = self.name;
    
    [self presentViewController:first animated:YES completion:^{
        
        
    }];
    
    [first release];
    
}

- (void)click {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [self.acView startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.acView stopAnimating];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
